var t = require("../../@babel/runtime/helpers/defineProperty"), a = getApp();

Page({
    data: {
        show: !1,
        columns: [],
        pickerValue: [ 0, 0, 0 ],
        imgheights: 0,
        nowDate: Date.parse(new Date()),
        form: {
            destination: "",
            terminus: "",
            flight: "",
            isDateName: ""
        },
        calendarShow: !1,
        selectShow: !1,
        minDate: new Date(2010, 0, 1).getTime(),
        maxDate: new Date(2010, 0, 31).getTime(),
        morePage: 1,
        page: 1
    },
    onLoad: function(t) {
        this.setData({
            minDate: new Date(this.fun_date(1)).getTime()
        });
    },
    goDetail: function() {
        wx.navigateTo({
            url: "/packageH/flightInformation/flightInformationDetailList/flightInformationDetailList"
        });
    },
    inpDes: function(a) {
        this.setData(t({}, "form.destination", a.detail));
    },
    inpTerm: function(a) {
        this.setData(t({}, "form.terminus", a.detail));
    },
    inpFlight: function(a) {
        this.setData(t({}, "form.flight", a.detail));
    },
    calendarTap: function() {
        this.setData({
            calendarShow: !0
        });
    },
    onClose: function() {
        this.setData({
            calendarShow: !1
        });
    },
    popClose: function(t) {
        this.setData({
            show: !1
        });
    },
    popShow: function() {
        this.setData({
            show: !0
        });
    },
    onReady: function() {},
    onShow: function() {
        this.getData();
    },
    imageLoad: function(t) {
        var a = 750 / (t.detail.width / t.detail.height);
        this.setData({
            imgheights: this.data.imgheights > a ? this.data.imgheights : a
        });
    },
    linkUrl: function(t) {
        console.log(t);
        var a = t.currentTarget.dataset.img;
        try {
            wx.navigateTo({
                url: a
            });
        } catch (t) {
            wx.redirectTo({
                url: a
            });
        }
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    dfsave: function(t) {
        var e = t.detail, i = {
            start_id: this.data.start_id,
            destination_id: this.data.destination_id,
            flight_id: this.data.flight_id,
            form_id: this.data.goodDYDormID,
            form_data: JSON.stringify(e),
            form_data_id: this.data.form_data_id ? this.data.form_data_id : "",
            flight_time: this.data.flight_time
        }, o = this;
        console.log(i);
        var s = a.getNetAddresss("plugin.flight-collect.frontend.index.save-diy-form-data");
        a._getNetWork({
            url: s,
            data: i,
            success: function(t) {
                var a = t.data;
                1 == a.result ? (wx.showToast({
                    title: "提交成功",
                    icon: "none",
                    duration: 1e3
                }), o.setData({
                    start_id: "",
                    destination_id: "",
                    flight_id: "",
                    flight_time: "",
                    form: {
                        destination: "",
                        terminus: "",
                        flight: "",
                        isDateName: ""
                    }
                })) : wx.showToast({
                    title: a.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    gofunarr: function() {
        if (a._isTextEmpty(this.data.start_id)) wx.showToast({
            title: "请填写出发地",
            duration: 1e3,
            icon: "none"
        }); else if (a._isTextEmpty(this.data.destination_id)) wx.showToast({
            title: "请填写目的地",
            duration: 1e3,
            icon: "none"
        }); else if (a._isTextEmpty(this.data.flight_id)) wx.showToast({
            title: "请填写航班",
            duration: 1e3,
            icon: "none"
        }); else if (a._isTextEmpty(this.data.flight_time)) wx.showToast({
            title: "请填写飞行计划日期",
            duration: 1e3,
            icon: "none"
        }); else {
            if (this.data.info.is_submit) {
                var e = new Date(), i = e.getFullYear(), o = e.getMonth() + 1, s = e.getDate(), n = Date.parse("".concat(i, "/").concat(o, "/").concat(s, " ").concat(this.data.startTime, ":00")), r = Date.parse("".concat(i, "/").concat(o, "/").concat(s, " ").concat(this.data.endTime, ":00"));
                if (!(this.data.nowDate >= n && this.data.nowDate <= r)) return void this.setData(t({}, "info.is_submit", 0));
                this.setData(t({}, "info.is_submit", 1)), this.selectComponent(".dsfrom").submit();
            }
        }
    },
    getData: function() {
        var e = this, i = a.getNetAddresss("plugin.flight-collect.frontend.index");
        a._getNetWork({
            url: i,
            success: function(a) {
                var i = a.data;
                if (1 == i.result) {
                    var o = i.data.information.replace(/<img/g, '<img style="width:100%"');
                    if (i.data.form_data.status = 0, e.setData({
                        columns: i.data.flight,
                        information: o,
                        info: i.data,
                        goodDYDormID: i.data.diyform,
                        dfData: i.data.form_data,
                        startTime: i.data.hours_start,
                        endTime: i.data.hours_end
                    }), i.data.is_submit) {
                        var s = new Date(), n = s.getFullYear(), r = s.getMonth() + 1, d = s.getDate();
                        console.log(n, r, d);
                        var l = Date.parse("".concat(n, "/").concat(r, "/").concat(d, " ").concat(i.data.hours_start, ":00")), h = Date.parse("".concat(n, "/").concat(r, "/").concat(d, " ").concat(i.data.hours_end, ":00"));
                        if (e.data.nowDate >= l && e.data.nowDate <= h ? e.setData(t({}, "info.is_submit", 1)) : e.setData(t({}, "info.is_submit", 0)), 
                        i.data.flight_time) {
                            var c = e.fun_date(Number(i.data.flight_time));
                            console.log(c);
                            var f = new Date(c).getTime();
                            console.log(f), e.setData({
                                maxDate: f
                            });
                        }
                    }
                    i.data.form_data && i.data.form_data.form_data_id && e.setData({
                        form_data_id: i.data.form_data.form_data_id
                    });
                } else console.log(i.msg);
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    bindChange: function(t) {
        this.setData({
            pickerValue: t.detail.value
        });
    },
    search: function(t) {
        console.log(t);
        var a = t.currentTarget.dataset.key;
        if ("des" == a) {
            this.setData({
                noKey: "des",
                selectShow: !0,
                moreList: []
            });
            var e = {
                detail: this.data.form.destination
            };
            this.searchGinfo(e);
        }
        if ("ter" == a) {
            this.setData({
                noKey: "ter",
                selectShow: !0,
                moreList: []
            });
            var i = {
                detail: this.data.form.terminus
            };
            this.searchGinfo(i);
        }
        if ("fli" == a) {
            this.setData({
                noKey: "fli",
                moreList: [],
                selectShow: !0
            });
            var o = {
                detail: this.data.form.flight
            };
            this.searchFlight(o);
        }
    },
    tapSelect: function(a) {
        console.log(a);
        var e = a.currentTarget.dataset.item;
        console.log(this.data.noKey), "des" == this.data.noKey ? (this.setData(t({
            start_id: e.id
        }, "form.destination", e.flight_city_name)), console.log(e, this.data.start_id)) : "ter" == this.data.noKey ? (this.setData(t({
            destination_id: e.id
        }, "form.terminus", e.flight_city_name)), console.log(e, this.data.start_id)) : "fli" == this.data.noKey && this.setData(t({
            flight_id: e.id
        }, "form.flight", e.flight_number)), this.setData({
            selectShow: !1
        });
    },
    searchFlight: function(t, e) {
        var i = this, o = this;
        wx.showLoading({
            title: "加载中"
        });
        var s = a.getNetAddresss("plugin.flight-collect.frontend.index.get-flight-number");
        a._getNetWork({
            url: s,
            data: {
                keyword: t.detail
            },
            success: function(t) {
                var a = t.data;
                1 == a.result ? ("more" == e ? i.setData({
                    moreList: o.data.moreList.concat(a.data.data)
                }) : i.setData({
                    moreList: a.data.data
                }), wx.hideLoading({
                    success: function(t) {}
                })) : (wx.hideLoading({
                    success: function(t) {}
                }), wx.showToast({
                    title: a.msg,
                    icon: "none",
                    duration: 1e3
                }));
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    selectShowClose: function() {
        this.setData({
            selectShow: !1
        });
    },
    tapMore: function() {
        var t = this.data.noKey;
        if (this.setData({
            page: this.data.page + 1
        }), "fli" == t) {
            var a = {
                detail: this.data.form.flight
            };
            this.searchFlight(a, "more");
        } else {
            var e = {
                detail: this.data.form.terminus
            };
            this.searchGinfo(e, "more");
        }
    },
    searchGinfo: function(t, e) {
        var i = this;
        console.log(t), "more" != e && this.setData({
            page: 1
        });
        var o = this, s = a.getNetAddresss("plugin.flight-collect.frontend.index.get-city");
        a._getNetWork({
            url: s,
            data: {
                keyword: t.detail,
                page: this.data.page
            },
            success: function(t) {
                var a = t.data;
                1 == a.result ? "more" == e ? i.setData({
                    moreList: o.data.moreList.concat(a.data.data),
                    morePage: a.data.last_page
                }) : i.setData({
                    moreList: a.data.data,
                    morePage: a.data.last_page
                }) : wx.showToast({
                    title: a.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    onConfirm: function(a) {
        var e, i = a.detail;
        this.calendarShow = !1;
        var o = this.formartDateTime(this.formatDate(i)) / 1e3;
        this.setData((t(e = {
            calendarShow: !1
        }, "form.isDateName", this.formatDate(i)), t(e, "flight_time", o), e));
    },
    formatDate: function(t) {
        return "".concat(t.getFullYear(), "-").concat(t.getMonth() + 1, "-").concat(t.getDate());
    },
    formartDateTime: function(t) {
        return t = t.replace(/-/g, "/"), t += " 00:00:00", new Date(t).getTime();
    },
    tapShow: function() {
        this.setData({
            columnsShow: !0
        });
    },
    tapCanle: function() {
        this.setData({
            columnsShow: !1
        });
    },
    fun_date: function(t) {
        var a = new Date(), e = a.getFullYear() + "-" + (a.getMonth() + 1) + "-" + a.getDate();
        console.log(e);
        var i = new Date(a);
        return i.setDate(a.getDate() + t), Number(i.getFullYear()) + "/" + Number(i.getMonth() + 1) + "/" + Number(i.getDate());
    }
});